<?php

/*
  SELECT table_name, column_name
  FROM information_schema.columns
  WHERE table_schema = 'foggy'
  order by table_name;
 */

function getTablesAndColumns() {
    $con = pg_connect("host=localhost port=5432 dbname=foggy user=postgres password=pickles") or die("Error in connection: " . pg_last_error());

    // execute query
    $sql = "SELECT table_name, column_name
        FROM information_schema.columns
        WHERE table_schema = 'foggy'
        order by table_name";
    $result = pg_query($con, $sql);
    if (!$result) {
        die("Error in SQL query: " . pg_last_error());
    }

    // iterate over result set
    // print each row
    echo "<table border='1'>";
    while ($row = pg_fetch_array($result)) {        
        echo "<tr>";
        echo "<td>";
        echo $row['table_name'];
        echo "</td>";
        echo "<td>";
        echo $row['column_name'];
        echo "</td>";
        echo "</tr>";        
    }
    echo "</table>";

    // free memory
    pg_free_result($result);

    // close connection
    pg_close($con);
}

?>
